package com.atguigu.auth.service.impl;

import com.atguigu.auth.mapper.OperLogMapper;
import com.atguigu.model.system.SysOperLog;
import com.atguigu.system.service.AsyncOperLogService;
import com.atguigu.vo.system.SysOperLogQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * ClassName AsyncOperLogServiceImpl
 * Package: com.atguigu.auth.service.impl
 * ProjectName guigu-oa-parent
 * Description:
 *
 * @Author: 比特张
 * @Create: 2023/7/1 - 22:41
 * @Version: v1.0
 */
@Service
public class AsyncOperLogServiceImpl extends ServiceImpl<OperLogMapper, SysOperLog> implements AsyncOperLogService {
    @Resource
    private OperLogMapper operLogMapper;

    @Override
    public void saveSysLog(SysOperLog sysOperLog) {
        operLogMapper.insert(sysOperLog);
    }

    @Override
    public IPage<SysOperLog> selectPage(Page<SysOperLog> pageParam, SysOperLogQueryVo sysOperLogQueryVo) {
        String title = sysOperLogQueryVo.getTitle();
        String operName = sysOperLogQueryVo.getKeyword();
        String createTimeBegin = sysOperLogQueryVo.getCreateTimeBegin();
        String createTimeEnd = sysOperLogQueryVo.getCreateTimeEnd();
        LambdaQueryWrapper<SysOperLog> wrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(title)) {
            wrapper.like(SysOperLog::getTitle, title);
        }
        if (!StringUtils.isEmpty(operName)) {
            wrapper.like(SysOperLog::getOperName, operName);
        }
        if (!StringUtils.isEmpty(createTimeBegin)) {
            wrapper.like(SysOperLog::getCreateTime, createTimeBegin);
        }
        if (!StringUtils.isEmpty(createTimeEnd)) {
            wrapper.like(SysOperLog::getCreateTime, createTimeEnd);
        }
        // 调用mapper方法
        Page<SysOperLog> sysOperLogPage = operLogMapper.selectPage(pageParam, wrapper);
        return sysOperLogPage;
    }
}
